import AdSearch from '@/components/AdSearch';
import AdSelect from '@/components/AdSelect';

export const codes = {
  select: 'PARTSOFFERPAGE_SELECT',
  add: 'PARTSOFFERPAGE_ADD',
  edit: 'PARTSOFFERPAGE_EDIT',
  showDetail: 'PARTSOFFERPAGE_VIEW',

  addInfo: 'PARTSOFFERPAGE_ADD_DETAILS',
  deleteInfo: 'PARTSOFFERPAGE_DEL_DETAILS',

  page: 'PARTSOFFERPAGE',
};

export const formate = 'YYYY-MM-DD HH:mm:ss';
export const formateNOSecond = 'YYYY-MM-DD HH:mm';

export const allDispatchType = {
  list: 'partsOffer/selectPartsOfferList', // 查询配件报价列表
  detail: 'partsOffer/selectPartsOfferDetail', // 查询配件报价详情
  info: 'partsOffer/selectPartsOfferInfo', // 查询配件报价明细
  save: 'partsOffer/savePartsOffer', // 保存或者保存并提交
  value: 'partsOffer/allValus',
  saveOrEditInfo: 'partsOffer/savePartsOfferInfo', // 提交并保存明细
  partsDetail: 'partsOffer/selectPartsDetail',
  deleteInfo: 'partsOffer/deletePartsInfo',
  setTabsName: 'common/setTabsName',
  queryPartsOfferDict: 'component/queryPartsOfferDict',
};

export const routeUrl = {
  add: '/carBasic/partsOfferList/addPartsOffer',
  edit: '/carBasic/partsOfferList/editPartsOffer',
};

export const allUrl = {
  userList: 'tms/tms-parts-offer/selectUserList_s',
  partsHierList: '/tms/tms-parts-offer/selectPartList_s',
};

export function getStateValue(code) {
  switch (code) {
    case 'WAIT':
      return '待生效';
    case 'VALID':
      return '有效';
    case 'EXPIRE':
      return '已过期';
  }
}

export function renderTableAdSelect({ key, data, value, props }) {
  let params = { onlyRead: true, value };
  if (key) {
    const { dictObject } = props;
    params = { data: dictObject[key], payload: { code: [key] }, ...params };
  } else {
    params = { data, ...params };
  }
  return <AdSelect {...params} />;
}

export function renderTableAdSearch({ value, props }) {
  const { searchValue } = props;
  if (!value || !searchValue) return '';
  const params = {
    onlyRead: true,
    value: searchValue[value],
    label: 'loginName',
    name: 'sysName',
  };
  return <AdSearch {...params} />;
}
